package pl.smath.operation;

import pl.smath.expression.ExponentiationTerm;
import pl.smath.expression.ProductTerm;
import pl.smath.expression.SumTerm;
import pl.smath.expression.Term;
import pl.smath.operation.basic.AddOp;
import pl.smath.operation.basic.ExpMultiplyOp;
import pl.smath.operation.basic.MultiplyAddOp;
import pl.smath.operation.basic.MultiplyOp;

public class BasicOp {

	/**
	 * t1 + t2
	 */
	public static Term add(Term t1, Term t2){
	
		AddOp op = new AddOp();
		return op.process(t1, t2);
	}
	
	/**
	 * (a * b)^n -> a^n * b^n
	 */
	public static Term expMultiply(ExponentiationTerm term){
	
		ExpMultiplyOp op = new ExpMultiplyOp();
		return op.process(term);
	}
	
	/**
	 * t1 * t2
	 */
	public static Term multiply(Term t1, Term t2){
	
		MultiplyOp op = new MultiplyOp();
		return op.process(t1, t2);
	}
	
	
	/**
	 * x*(a+b) - > x*a + x*b
	 */
	public static Term multiplyAdd(Term t1, SumTerm t2){
	
		MultiplyAddOp op = new MultiplyAddOp();
		return op.process(t1, t2);
	}
	
	
	/**
	 * Upraszcza wyrazenie poprzez sumowanie lub wymnozenie podwyrazen
	 * @param term
	 */
	public static Term simplify(Term term){
		
		if(term instanceof SumTerm){
			return new AddOp().processAll((SumTerm)term);
		}
		else if(term instanceof ProductTerm){
			return new MultiplyOp().processAll((ProductTerm)term);
		}
		
		return null;
	}
}
